package com.usian.skill.controller;

import com.usian.skill.common.CodeMsg;
import com.usian.skill.common.Result;
import com.usian.skill.pojo.OrderInfo;
import com.usian.skill.pojo.SkillUser;
import com.usian.skill.service.GoodsService;
import com.usian.skill.service.OrderInfoService;
import com.usian.skill.service.SkillUserService;
import com.usian.skill.vo.GoodsVo;
import com.usian.skill.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("/order")
public class OrderController {

	@Autowired
	SkillUserService userService;
	
	/*@Autowired
	RedisService redisService;*/
	
	@Autowired
	OrderInfoService orderService;
	
	@Autowired
	GoodsService goodsService;
	
    @RequestMapping("/detail")
    @ResponseBody
    public Result info(HttpSession session, Model model, SkillUser user,
									  @RequestParam("orderId") long orderId) {
		String s=(String)session.getAttribute("userId");
		String id=session.getId();
		if (s==null){
			return Result.error(CodeMsg.SESSION_ERROR);

		}
		OrderInfo order=orderService.getById(orderId);
		if (order==null){
			return Result.error(CodeMsg.ORDER_NOT_EXIST);
		}
		Long goodsId=order.getGoodsId();
		GoodsVo goodsVo=goodsService.getgoodsvobyid(goodsId);
		OrderDetailVo vo=new OrderDetailVo();
		vo.setOrder(order);
		vo.setGoods(goodsVo);


		return Result.success(vo);
    }
    
}
